package com.tianshuo.construct.main;

import com.tianshuo.construct.ConstructConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;

import java.util.Map;

/**
 *  测试spring中环境变量信息
 *
 *  SystemEnvironment 系统环境变量
 *  SystemProperties jvm环境变量
 *
 *  MutablePropertySources 中既有系统环境变量，又有jvm的环境变量
 *
 */
public class EnvironmentApplicationContext {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConstructConfig.class);
        // 系统管理变量
        Map<String, Object> systemEnvironment = applicationContext.getEnvironment().getSystemEnvironment();
        System.out.println(systemEnvironment);
        System.out.println("___----______");
        // jvm环境变量
        Map<String, Object> systemProperties = applicationContext.getEnvironment().getSystemProperties();
        System.out.println(systemProperties);
        System.out.println("___----______");
        // 用于读取配置文件中的变量信息
        MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
        System.out.println(propertySources);

        System.out.println("___----______");
        System.out.println(applicationContext.getEnvironment().getProperty("JAVA_HOME"));
        System.out.println(applicationContext.getEnvironment().getProperty("age"));


    }
}
